package com.chenfan.mcn.component.dict;

import com.chenfan.mcn.clients.baseinfo.BaseCustomer;
import com.chenfan.mcn.clients.baseinfo.BaseInfoClient;
import com.chenfan.common.extension.context.SpringContextHolder;
import com.chenfan.common.extension.dict.DictTranslator;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

/**
 * 客户（对方公司）ID翻译成名称
 *
 * @author wulg
 * @date 2021-12-11
 **/
public class CustomerIdTranslator implements DictTranslator<Long, String> {

    @Override
    public String translate(Long customerId) {
        BaseInfoClient baseInfoClient = SpringContextHolder.getBean(BaseInfoClient.class);
        Map<Long, BaseCustomer> customerMapping = Objects.requireNonNull(baseInfoClient.getMcnCustomerByIds(Arrays.asList(customerId))).getObj();
        if(customerMapping.containsKey(customerId)) {
            return customerMapping.get(customerId).getCustomerNameC();
        }
        return customerId.toString();
    }
}
